package edu.upc.clase.demo.controller;

import edu.upc.clase.demo.entity.JsonResponse;
import edu.upc.clase.demo.entity.Negocio;
import edu.upc.clase.demo.service.NegocioService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *
 * @author Profesores
 */
@Controller
public class NegocioController {
    
    @Autowired
    NegocioService negocioService;
    
    @RequestMapping(value = "/listarNegocios", method = RequestMethod.GET, produces = "application/json")
    public @ResponseBody JsonResponse listarNegocios() {
        Boolean success = true;
        String errorMessage = "";
        List<Negocio> negocios = null;
        try {
            negocios = negocioService.obtenerListadoNegocio();
        } catch(Exception e) {
            errorMessage = e.getMessage();
            success = false;
        }
        
        return new JsonResponse(success,errorMessage,negocios);
    }    
    
}
